import { SlateElement } from "@wangeditor/editor";
import { DOMElement } from "@wangeditor/editor/dist/editor/src/utils/dom";

function parseHtml(elem: DOMElement): SlateElement {
  const title = elem.getAttribute("data-title") || "";
  const address = elem.getAttribute("data-address") || "";
  const price = elem.getAttribute("data-price") || "";
  const tags = elem.getAttribute("data-tags") || "";
  const cover = elem.getAttribute("data-cover") || "";
  const disadvantage_color = elem.getAttribute("data-disadvantage_color") || "";
  const disadvantage_cover = elem.getAttribute("data-disadvantage_cover") || "";
  const disadvantage_name = elem.getAttribute("data-disadvantage_name") || "";
  const status = elem.getAttribute("data-status") || "";
  const status_background = elem.getAttribute("data-status_background") || "";
  const status_color = elem.getAttribute("data-status_color") || "";
  const area = elem.getAttribute("data-area") || "";
  return {
    type: "build-card",
    title,
    address,
    price,
    tags,
    disadvantage_color,
    disadvantage_cover,
    disadvantage_name,
    status,
    status_background,
    status_color,
    cover,
    area,
    children: [{ text: "" }]
  } as SlateElement;
}

const parseHtmlConf = {
  selector: 'div[data-w-e-type="build-card"]',
  parseElemHtml: parseHtml
};

export default parseHtmlConf;
